from configparser import ConfigParser

from encryption import getDataAes

conf = ConfigParser()

try:
    conf.read("config.ini")

    secret = conf.get('mqtt', 'secret')

    mqtthost = conf.get("mqtt", "host")
    mqttport = conf.getint("mqtt", "port")
    mqttuser = conf.get("mqtt", "user")
    mqttpassword = conf.get("mqtt", "password")
    mqttTLS = conf.getboolean("mqtt", "mqtt_tls")

    redishost = conf.get("redis", "host")
    redisport = conf.getint("redis", "port")
    redispwd = conf.get("redis", "password")
    redislibrary = conf.get("redis", "library")
except Exception as e:
    print(e)

    secret = 'gi4jv3=9bd!!5)-f3xr6&4p7@*($0b_yryq8uoz1d9e-msv'

    mqtthost = '127.0.0.1'
    mqttport = 1883
    mqttuser = 'admin'
    mqttpassword = 'admin'
    mqttTLS = False

    redishost = '127.0.0.1'
    redisport = '6379'
    redispwd = '000000'
    redislibrary = "1"


try:

    redispwd = getDataAes(secret, redispwd)
    mqttuser = getDataAes(secret, mqttuser)
    mqttpassword = getDataAes(secret, mqttpassword)
except Exception as e:

    redispwd = '000000'
    mqttuser = 'admin'
    mqttpassword = 'admin'